// 第二种写法: 动态获取pb文件
// node src/main/js/grpcClient2.js
const PROTO_FILE_PATH = 'src/main/protoBuf/Student.proto'

const grpc = require('grpc')
const protoLoader = require('@grpc/proto-loader')
const packageDefinition = protoLoader.loadSync(PROTO_FILE_PATH, {
    keepCase: true,
    longs: String,
    enums: String,
    defaults: true,
    oneofs: true
});

const grpcService = grpc.loadPackageDefinition(packageDefinition).com.shengsiyuan.proto;
const client = new grpcService.StudentService('localhost:8899', grpc.credentials.createInsecure());

client.getRealNameByUsername({username: '王五啊'}, function (error, respData) {
    console.log(respData);
});
